layui.extend({
    tableMerge: '/evaluation/public/layui_tableMerge/tableMerge'
}).use([ "form","table",'layer',"laydate",'tableMerge'], () => (function (
    {form, table, layer, laydate,tableMerge,startLayDate,endLayDate,tableDoneDatas,beforeTableDoneSelect,exportExcelParam, assessStatisticalTableIns,selectDatas,page,url,contentType, ok, AjaxFn}) {

    startLayDate = laydate.render({
        elem: '#start',
        theme:"#01aaed",
        type:"month",
        format: 'yyyy-MM-dd',
        max: new Date().getTime(),
        value: new Date(),
        calendar: true,
        /*done: (value, date, endDate,v=[],minDate={})=>(
            v = value.split("-"),minDate.year=v[0],minDate.month=v[1]-1,
                endLayDate.config.min=minDate, $("#end").val()!=""?$("#end").val()<value?$("#end").val(""):'':''
        )*/
    }),
    /*endLayDate  = laydate.render({
        elem: '#end',
        theme: '#01aaed',
        type:"month",
        format: 'yyyy-MM-dd',
        max: new Date().getTime(),
        calendar: true
    }),*/

    selectDatas = (()=>(res = AjaxFn("/evaluation/staff/staffSelectDatas","",{}),{positions='',factorys='',teams='',appraises='',p=''}=res,
        positions !='' && positions.length>0?(p=`<option value=""></option>`,$.each(positions,(i,v)=>(p+=`<option value="${v.vpositionid}">${v.vpositionname}</option>`)),$('select[name=vpositionid]').html(p)):'',
        factorys !='' && factorys.length>0?(p=`<option value=""></option>`,$.each(factorys,(i,v)=>(p+=`<option value="${v.scode}">${v.vname}</option>`)),$('select[name=vfactoryflg]').html(p)):'',
        teams !='' && teams.length>0?(p=`<option value=""></option>`,$.each(teams,(i,v)=>(p+=`<option value="${v.vteamid}">${v.vteamname}</option>`)),$('select[name=vteamid]').html(p)):''
        /*appraises !='' && appraises.length>0?(p=`<option value=""></option>`,$.each(appraises,(i,v)=>(p+=`<option value="${v.scode}">${v.vname}</option>`))
            ,$('select[name=vappraiseflg]').html(p)):''*/))(),form.render(),

    StatisticalTableIns = table.render({
        elem: '#StatisticalTable',
        /*url: url + "StatisticalTable",*/
        method: 'post',
        contentType,
        page,
        cols: [
            [
                {title: '序号',type: 'numbers', fixed: "left", unresize: true, align: "center", width: 50, minWidth: 30},
                {field: 'vstaffname', title: '员工姓名',fixed: "left",  unresize: true, align: "center",minWidth: 120},
                {field: 'vpositionname',title: '职位',fixed: "left",  unresize: true, align: "center", minWidth: 120},
                {field: 'vfactoryflgname',title: '工厂',fixed: "left",  unresize: true, align: "center",minWidth: 120},
                {field: 'vteamname',title: '班组',fixed: "left",  unresize: true, align: "center",minWidth: 120},

                {field: 'grossscore',title: '分数合计',fixed: "left", unresize: true, align: "center",minWidth: 90},

                {field: 'vyearmonth',title: '评定年月', fixed: "left",  unresize: true, align: "center", minWidth: 90},

                {field: 'zwiscore', title: '自我评定', unresize: true, align: "center",minWidth: 90},
                {field: 'zwfpercentagescore', title: '百分比分数', unresize: true, align: "center", minWidth: 100},

                {field: 'bziscore', title: '班组评定', unresize: true, align: "center",minWidth: 90},
                {field: 'bzfpercentagescore', title: '百分比分数', unresize: true, align: "center", minWidth: 100},

                {field: 'kuiscore', title: '客户评定', unresize: true, align: "center",minWidth: 90},
                {field: 'kufpercentagescore', title: '百分比分数', unresize: true, align: "center", minWidth: 100},

                {field: 'pdiscore', title: '评定组评定', unresize: true, align: "center",minWidth: 100},
                {field: 'pdfpercentagescore', title: '百分比分数', unresize: true, align: "center", minWidth: 100},


            ]
        ],
        data:[],
        done: (res, curr, count) => (console.log("res=====",res),tableDoneDatas = res.data)
    }),

    form.on('submit(assessStatisticalFormSubmit)',({field,obj={}})=>{
        obj.where=field,obj.page={curr:1},obj.url=url + "StatisticalTable",
        StatisticalTableIns.reload(obj),
        beforeTableDoneSelect = field;
        return false;
    }),

    $(".exportExcel").click((param='')=>(
            tableDoneDatas.length>0?(
                window.location.href=url+"exportExcel?"+exportExcelParam(beforeTableDoneSelect)
            ):layer.msg("没有可导出的数据",{icon:7,tiem:1000})
        )
    )

})({
    form: layui.form,
    table: layui.table,
    layer: layui.layer,
    laydate: layui.laydate,
    tableMerge : layui.tableMerge,
    startLayDate:'',
    endLayDate:'',
    StatisticalTableIns: '',
    tableDoneDatas:[],
    beforeTableDoneSelect:{},
    selectDatas:[],
    url: "/evaluation/AssessStatistical/",
    contentType: 'application/json;charset=utf-8',
    page: {
        first: '首页',
        last: '尾页',
        prev: '上一页',
        next: '下一页',
        layout: ['count', 'prev', 'page', 'next'], groups: 5,
        theme: '#1e9fff',
        limits: [10, 20, 30, 40, 50],
    },
    ok: function (msg, icon) {
        layui.layer.confirm(msg, {
            id: "ok",
            icon: icon,
            anim: 4,
            title: '提示',
            btn: ['确定'],
            closeBtn: false,
            success: function (layero) {
                var btn = layero[0].getElementsByClassName('layui-layer-btn')[0].getElementsByTagName('A')[0];
                btn.href = 'javascript:void(0)';
                btn.focus();
            },
            yes: function (index, layero) {
                layer.close(index); //再执行关闭
            },
            end: function () {
                var index2 = parent.layer.getFrameIndex(window.name);
                parent.layer.closeAll();
            }
        });
    },
    AjaxFn: function (url, data, resource) {
        $.ajax({
            url,
            contentType: 'application/json;charset=utf-8',
            type: 'post',
            async: false,
            data,
            success: function (res) {
                let {msg='',code=''} =res;
                msg=='' && code==''? top.location.reload() : "";
                resource = res;
            }
        });
        return resource;
    },
    exportExcelParam:(field,str='')=>{for (let i  in field){str += i+"="+ field[i]+"&"}return str.substring(0,str.length-1)}
}))
